//
//  AEMyExchangeViewModel.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/13.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEMyExchangeViewModel.h"

@implementation AEMyExchangeViewModel

- (void)initialize {
    [super initialize];
    
    
}

- (void)setupData {
    
//    @[@"全部", @"待领取", @"已领取"];
    if ([objectNull(self.statusName) isEqualToString:@"待领取"]) {
        self.receiveType = @(0);
    } else if ([objectNull(self.statusName) isEqualToString:@"已领取"]) {
        self.receiveType = @(1);
    } else {
        self.receiveType = nil;
    }
    
    /*
    AEMyExchangeModel *model = [[AEMyExchangeModel alloc] init];
    model.orderNo = @"4242424";
    model.imgUrl = @"http://img.alicdn.com/img/i1/15087688/O1CN01wyHyt126f9rF0vDeT_!!0-saturn_solar.jpg_580x580q90.jpg";
    model.goodsName = @"户外背包";
    model.cnt = @"899";
    model.remark = @"积分商品一经兑换，概不退换";
    model.status = @"1"; // 1 待领取；2 已领取
    model.createTime = @"2022-08-02 13:24:00";
    model.receiveGoodsWay = @"用户请联系客服并领取";
    model.payment = @"积分支付";
    [self.dataList addObject:model];
    
    model = [[AEMyExchangeModel alloc] init];
    model.orderNo = @"4242424";
    model.imgUrl = @"https://nimg.ws.126.net/?url=http%3A%2F%2Fcms-bucket.ws.126.net%2F2024%2F1014%2Fe38eee31p00slcev3001ic0009c0070c.png&thumbnail=140y88&quality=100&type=jpg";
    model.goodsName = @"户外背包";
    model.cnt = @"899";
    model.remark = @"积分商品一经兑换，概不退换";
    model.status = @"2"; // 1 待领取；2 已领取
    model.createTime = @"2022-08-02 13:24:00";
    model.receiveGoodsWay = @"用户请联系客服并领取";
    model.payment = @"积分支付";
    [self.dataList addObject:model];
    
    model = [[AEMyExchangeModel alloc] init];
    model.orderNo = @"4242424";
    model.imgUrl = @"https://nimg.ws.126.net/?url=http%3A%2F%2Fcms-bucket.ws.126.net%2F2024%2F1014%2Fe38eee31p00slcev3001ic0009c0070c.png&thumbnail=140y88&quality=100&type=jpg";
    model.goodsName = @"户外背包";
    model.cnt = @"899";
    model.remark = @"积分商品一经兑换，概不退换";
    model.status = @"1"; // 1 待领取；2 已领取
    model.createTime = @"2022-08-02 13:24:00";
    model.receiveGoodsWay = @"用户请联系客服并领取";
    model.payment = @"积分支付";
    [self.dataList addObject:model];
    
    model = [[AEMyExchangeModel alloc] init];
    model.orderNo = @"4242424";
    model.imgUrl = @"https://nimg.ws.126.net/?url=http%3A%2F%2Fcms-bucket.ws.126.net%2F2024%2F1014%2Fe38eee31p00slcev3001ic0009c0070c.png&thumbnail=140y88&quality=100&type=jpg";
    model.goodsName = @"户外背包";
    model.cnt = @"899";
    model.remark = @"积分商品一经兑换，概不退换";
    model.status = @"1"; // 1 待领取；2 已领取
    model.createTime = @"2022-08-02 13:24:00";
    model.receiveGoodsWay = @"用户请联系客服并领取";
    model.payment = @"积分支付";
    [self.dataList addObject:model];
    
    model = [[AEMyExchangeModel alloc] init];
    model.orderNo = @"4242424";
    model.imgUrl = @"http://img.alicdn.com/img/i1/15087688/O1CN01wyHyt126f9rF0vDeT_!!0-saturn_solar.jpg_580x580q90.jpg";
    model.goodsName = @"户外背包";
    model.cnt = @"899";
    model.remark = @"积分商品一经兑换，概不退换";
    model.status = @"2"; // 1 待领取；2 已领取
    model.createTime = @"2022-08-02 13:24:00";
    model.receiveGoodsWay = @"用户请联系客服并领取";
    model.payment = @"积分支付";
    [self.dataList addObject:model];
     */
}


/// 我的兑换信息
/// - Parameter completion: completion description
- (void)requestWithMyExchanageInfos:(RequestCompletionBlock)completion {
    @weakify(self);
    AEConfirmOrderInfosRequest *request = [[AEConfirmOrderInfosRequest alloc] initWithReceiveType:self.receiveType];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            [self.dataList removeAllObjects];
            [self.dataList addObjectsFromArray:respond.data];
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

/// 确认
/// - Parameters:
///   - orderCode: orderCode description
///   - completion: completion description
- (void)requestWithOrderReceice:(NSString *)orderCode completion:(RequestCompletionBlock)completion {
    @weakify(self);
    AEOrderInfoReceiveRequest *request = [[AEOrderInfoReceiveRequest alloc] initWithOrderCode:orderCode];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
//        EDSRespondDataEntity *respond = request.responseModelObject;
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

@end
